package com.shijie.newvideo.down;

import android.content.Context;

import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.upstream.cache.CacheEvictor;
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;

import java.io.File;

public class CacheUtil {
    private static SimpleCache simpleCache;

    public static SimpleCache getSimpleCache(Context context) {
        if (simpleCache == null) {
            File cacheDir = new File(context.getCacheDir(), "video_cache");
            long cacheSize = 100 * 1024 * 1024; // 设置缓存大小为 100MB
            CacheEvictor cacheEvictor = new LeastRecentlyUsedCacheEvictor(cacheSize);
            ExoDatabaseProvider databaseProvider = new ExoDatabaseProvider(context);

            simpleCache = new SimpleCache(cacheDir, cacheEvictor, databaseProvider);
        }
        return simpleCache;
    }
}
